package com.ruoyi.basedata.controller;

import java.util.HashMap;
import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.basedata.domain.ResponseMessage;
import com.ruoyi.basedata.dto.msg.MsgDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.basedata.domain.Msg;
import com.ruoyi.basedata.service.IMsgService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 消息通知Controller
 * 
 * @author ruoyi
 * @date 2024-10-25
 */
@RestController
@RequestMapping("/msg")
public class MsgController extends BaseController
{
    @Autowired
    private IMsgService msgService;

    /**
     * 查询消息通知列表
     */
    @RequiresPermissions("basedata:msg:list")
    @GetMapping("/list")
    public TableDataInfo list(Msg msg)
    {
        startPage();
        List<Msg> list = msgService.selectMsgList(msg);
        return getDataTable(list);
    }
    private Logger logger = LoggerFactory.getLogger(MsgController.class);

    @GetMapping("/getMsg")
    @RequiresPermissions("basedata:msg:getMsg")
    public AjaxResult getMsg(MsgDto MsgDto){
        Map map = new HashMap<>();
        map.put("userId", MsgDto.getUserId());
        map.put("pageNo", MsgDto.getPageNo());
        map.put("pageSize", MsgDto.getPageSize());
        logger.info(" FinerMsgController   getMsg   start.....map"+map);
        return  msgService.getMsg(map);
    }

    @RequiresPermissions("basedata:msg:getUReadCount")
    @GetMapping(value = "/count/{userId}")
    public AjaxResult getUReadCount(@PathVariable("userId") int userId){
        logger.info(" FinerMsgController   getMsg   start.....userId"+userId);
        return msgService.getUReadCount(userId);
    }

    @RequiresPermissions("basedata:msg:query")
    @GetMapping(value = "/{id}")
    public AjaxResult updMsg(@PathVariable("id") int id)
    {
        return success(msgService.updMsgStatus(id));
    }

    /**
     * 导出消息通知列表
     */
    @RequiresPermissions("basedata:msg:export")
    @Log(title = "消息通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Msg msg)
    {
        List<Msg> list = msgService.selectMsgList(msg);
        ExcelUtil<Msg> util = new ExcelUtil<Msg>(Msg.class);
        util.exportExcel(response, list, "消息通知数据");
    }

    /**
     * 获取消息通知详细信息
     */
    /**
     * 新增消息通知
     */
    @RequiresPermissions("basedata:msg:add")
    @Log(title = "消息通知", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Msg msg)
    {
        return toAjax(msgService.insertMsg(msg));
    }

    /**
     * 修改消息通知
     */
    @RequiresPermissions("basedata:msg:edit")
    @Log(title = "消息通知", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Msg msg)
    {
        return toAjax(msgService.updateMsg(msg));
    }

    /**
     * 删除消息通知
     */
    @RequiresPermissions("basedata:msg:remove")
    @Log(title = "消息通知", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(msgService.deleteMsgByIds(ids));
    }
}
